﻿using NPOI.HWPF;
using NPOI.POIFS.FileSystem;
using NPOI.XWPF.UserModel;
using System.Text;

namespace WordHandlerConsole
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            string filePath = @"C:\Users\Administrator\Desktop\b.doc";
            POIFSFileSystem fs = new POIFSFileSystem(File.OpenRead(filePath));
            HWPFDocument doc = new HWPFDocument(fs);

            //using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            //{
            //    HWPFDocument doc = new HWPFDocument(fs);
            //    var a = 1;
            //}
              var ab = 1;
            //foreach (var para in doc.Paragraphs)
            //{
            //    Console.WriteLine(para.ParagraphText);
            //}

            // 遍历文档的表格
           


            //string filePath = @"C:\Users\Administrator\Desktop\a.docx";
            #region 
            //try
            //{
            //    using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            //    {
            //        XWPFDocument doc = new XWPFDocument(fs);

            //        // 遍历文档的段落
            //        foreach (var para in doc.Paragraphs)
            //        {
            //            Console.WriteLine(para.ParagraphText);
            //        }

            //        // 遍历文档的表格
            //        foreach (var table in doc.Tables)
            //        {
            //            foreach (var row in table.Rows)
            //            {
            //                foreach (var cell in row.GetTableCells())
            //                {
            //                    Console.Write(cell.GetText() + "\t");
            //                }
            //                Console.WriteLine();
            //            }
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine($"Error reading the document: {ex.Message}");
            //}
            #endregion
            Console.WriteLine("Hello, World!");

            Console.ReadKey();
        }
    }
}